# Maintainer: StableAgOH <stagoh17@gmail.com>

_realname=keepassxc
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.7.10
pkgrel=2
pkgdesc="A modern, secure, and open-source password manager that stores and manages your most sensitive information (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://keepassxc.org/'
msys2_repository_url='https://github.com/keepassxreboot/keepassxc'
license=('spdx:GPL-2.0 OR GPL-3.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-asciidoctor"
             "${MINGW_PACKAGE_PREFIX}-qt5-tools")
depends=("${MINGW_PACKAGE_PREFIX}-argon2"
         "${MINGW_PACKAGE_PREFIX}-libbotan"
         "${MINGW_PACKAGE_PREFIX}-minizip"
         "${MINGW_PACKAGE_PREFIX}-qrencode"
         "${MINGW_PACKAGE_PREFIX}-qt5-base"
         "${MINGW_PACKAGE_PREFIX}-qt5-svg"
         "${MINGW_PACKAGE_PREFIX}-readline")
source=("https://github.com/keepassxreboot/${_realname}/releases/download/${pkgver}/${_realname}-${pkgver}-src.tar.xz"
        "0001-fix-cmake-install.patch"
        "0002-mingw-windres.patch"
        "0003-fix-resource-dir.patch")
sha256sums=('5ce76d6440986c24842585f019d5f3cadc166fa71fc911a4fe97b8bbc4819dfa'
            '0f4bb341015b1d69e4cfce5b8cf12bee09dc27ff3cdb84ab8d36db23e265b22f'
            'de85c69ca29c44605549dc25342978ff328f1d632cd469ff4c09f016edbb982b'
            'fff46c70d2f3cfa058f1b8d2b17c81db7f22eeebf00cd2a9b98fd9db5f750e64')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  patch -Np1 -i "${srcdir}"/0001-fix-cmake-install.patch
  patch -Np1 -i "${srcdir}"/0002-mingw-windres.patch
  patch -Np1 -i "${srcdir}"/0003-fix-resource-dir.patch
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    "${MINGW_PREFIX}"/bin/cmake.exe \
      -GNinja \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      -DWITH_XC_ALL=ON \
      -DWITH_XC_UPDATECHECK=OFF \
      -DWITH_TESTS=OFF \
      ../${_realname}-${pkgver}

  "${MINGW_PREFIX}"/bin/cmake.exe --build .
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  "${MINGW_PREFIX}"/bin/cmake.exe --build . --target test
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install .

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
